package com.download.web.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.download.web.entity.BusArticle;
import com.download.web.entity.BusArticleDownload;
import com.download.web.entity.model.Page;
import com.download.web.mapper.BusArticleDownloadMapper;
import com.download.web.service.IBusArticleDownloadService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @description:
 * @author: cmy
 * @create: 2019-02-21 17:03
 **/
@Service
public class BusArticleDownloadImpl extends ServiceImpl<BusArticleDownloadMapper, BusArticleDownload> implements IBusArticleDownloadService {

    @Resource
    private BusArticleDownloadMapper downloadMapper;

    @Override
    public Page<BusArticleDownload> downloadListPage(Integer artId, Integer pageIndex, Integer pageSize) {
        List<BusArticleDownload> downloads=downloadMapper.downloadListByArticle(artId,pageIndex,pageSize);
        return new Page<>(downloads,downloadMapper.downloadCountByArticle(artId),pageIndex,pageSize);
    }

    @Override
    public String addArticleDownload(BusArticleDownload articleDownload) {
        articleDownload.setCreateTime(new Date());
        save(articleDownload);
        return articleDownload.getId().toString();
    }
}
